package com.js.purs.controller;

import java.text.ParseException;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.js.purs.domain.PurProdInfo;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurProdBudget;
import com.js.purs.service.IPurProdBudgetService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购Controller
 * 
 * @author lzq
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/budget")
public class PurProdBudgetController extends BaseController
{
    @Autowired
    private IPurProdBudgetService purProdBudgetService;


    /**
     * 查询采购列表
     */
    @RequiresPermissions("budget:budget:list")
    @GetMapping("/list")
    public TableDataInfo list(PurProdBudget purProdBudget)
    {
        startPage();
        List<PurProdBudget> list = purProdBudgetService.selectPurProdBudgetList(purProdBudget);
        return getDataTable(list);
    }

    /**
     * 导出采购列表
     */
    @RequiresPermissions("budget:budget:export")
    @Log(title = "采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurProdBudget purProdBudget)
    {
        List<PurProdBudget> list = purProdBudgetService.selectPurProdBudgetList(purProdBudget);
        ExcelUtil<PurProdBudget> util = new ExcelUtil<PurProdBudget>(PurProdBudget.class);
        util.exportExcel(response, list, "采购数据");
    }

    /**
     * 获取采购详细信息
     */
    @RequiresPermissions("budget:budget:query")
    @GetMapping(value = "/{bgId}")
    public AjaxResult getInfo(@PathVariable("bgId") String bgId)
    {
        return success(purProdBudgetService.selectPurProdBudgetByBgId(bgId));
    }

    /**
     * 新增采购
     */
    @RequiresPermissions("budget:budget:add")
    @Log(title = "采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurProdBudget purProdBudget)
    {
        return toAjax(purProdBudgetService.insertPurProdBudget(purProdBudget));
    }

    /**
     * 修改采购
     */
    @RequiresPermissions("budget:budget:edit")
    @Log(title = "采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurProdBudget purProdBudget)
    {
        return toAjax(purProdBudgetService.updatePurProdBudget(purProdBudget));
    }

    /**
     * 删除采购
     */
    @RequiresPermissions("budget:budget:remove")
    @Log(title = "采购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bgIds}")
    public AjaxResult remove(@PathVariable String[] bgIds)
    {
        return toAjax(purProdBudgetService.deletePurProdBudgetByBgIds(bgIds));
    }


    /**
     *
     * 批量添加
     * */
    @PostMapping("/budList")
    public AjaxResult insetBudGetList(@RequestBody List<PurProdBudget> budgetList){
        return toAjax(purProdBudgetService.insertPurProdBudgetBatch(budgetList));
    }

    /**
     *
     * 批量修改+增加
     * */
    @PostMapping("/updateOrInsertBudGet")
    public AjaxResult updateOrInsertBudGet(@RequestBody List<PurProdBudget> budgetList){

        return toAjax(purProdBudgetService.updateOrInsertBudGet(budgetList));
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBudGet")
    public AjaxResult deleteBudGet(@RequestBody List<PurProdBudget> budGetList) throws ParseException {
        return toAjax(purProdBudgetService.deleteBudGet(budGetList));
    }

}
